package cn.com.eado.uwallpaper.net;

import android.app.Activity;
import android.app.ProgressDialog;
import android.widget.Toast;

import com.squareup.okhttp.Callback;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;

/**
 * Created by lcy on 2015/11/24.
 */
public abstract class MyCallBack implements Callback {

    ProgressDialog dialog;
    private Activity activity;
    public MyCallBack(Activity activity, ProgressDialog dialog) {
        this.activity = activity;
        this.dialog=dialog;
    }
    @Override
    public void onFailure(Request request, IOException e) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(activity,"请求网络失败",Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });
    }

    @Override
    public void onResponse(Response response) throws IOException {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
//                Toast.makeText(activity,"请求网络成功",Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });
    }
}
